package com.kronos.gui;

import java.util.ArrayList;
import java.util.List;

import com.badlogic.gdx.input.GestureDetector;
import com.kronos.game.KronosGame;

public class Canvas {
	private KronosGame game;
	private List<Drawable> objects;
	private GestureDetector gd;
	public Canvas(KronosGame game) {
		this.game = game;
		this.objects = new ArrayList<Drawable>();
	}

	public void addDrawable(Drawable obj) {
		this.objects.add(obj);
		game.addInputMultiplexer(obj);
		gd = new GestureDetector(obj); 
		game.addInputMultiplexer(gd);
	}
	public void addDrawable(Drawable... obj) {
		for (Drawable drawable : obj) {
			this.objects.add(drawable);
			game.addInputMultiplexer(drawable);
		}
	}
	public void drawDrawable(Drawable obj) {
		obj.update();
		obj.render(game.getSpriteBatch());
	}
	public void drawDrawables(Drawable... obj) {
		for (Drawable drawable : obj) {
			drawable.update();
			drawable.render(game.getSpriteBatch());
		}
	}

	public void removeDrawable(Drawable obj) {
		this.objects.remove(obj);
	}

	public void removeListener(Drawable obj) {
		game.removeInputMultiplexer(obj);
		game.removeInputMultiplexer(gd);
	}

	public void clearAll() {
		for (Drawable obj : objects) game.removeInputMultiplexer(obj);
		this.objects.clear();
	}

	public List<Drawable> getDrawables() {
		return this.objects;
	}
}
